<?php

namespace app\utils;

use Illuminate\Support\Facades\Redis;

/**
 * Class CacheUtil
 * @package App\Utils
 *
 * Redis 缓存服务
 */
class CacheUtil
{
    private static array $clients = [];

    public const DEFAULT = 'default';

    /**
     * @param null $name
     * @return mixed|\Redis
     */
    public static function client($name = self::DEFAULT)
    {
        if (isset(self::$clients[$name])) {
            $redis = self::$clients[$name];
        } else {
            $redis = Redis::connection($name);
            self::$clients[$name] = $redis;
        }

        return $redis->client();
    }
}
